package com.mengniu.commerce.sync.controller;


import com.alibaba.fastjson.JSONObject;
import com.mengniu.commerce.common.core.domain.R;
import com.mengniu.commerce.common.core.web.controller.BaseController;
import com.mengniu.commerce.common.log.annotation.Log;
import com.mengniu.commerce.common.log.enums.BusinessType;
import com.mengniu.commerce.sync.api.domain.PointsIncreaseModel;
import com.mengniu.commerce.sync.api.domain.PointsReduceModel;
import com.mengniu.commerce.sync.api.dto.RetryDTO;
import com.mengniu.commerce.sync.service.PointsService;
import lombok.extern.slf4j.Slf4j;
import org.simpleframework.xml.core.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 积分controller
 *
 * @author zfw
 */
@RestController
@RequestMapping("/point")
@Slf4j
public class PointController extends BaseController
{
       @Autowired
    private PointsService pointsService;

    @Log(title = "扣减积分管理", businessType = BusinessType.INSERT)
    @PostMapping("/reduce")
    public R<?> pointsReduce(@RequestBody @Valid PointsReduceModel pointsReduceModel, String source)
    {
        log.info("扣减积分参数为:{},{}", JSONObject.toJSONString(pointsReduceModel),source);
        RetryDTO retryDTO = new RetryDTO();
        //todo RetryDTO
        return R.ok(pointsService.pointsReduce(pointsReduceModel,retryDTO));

    }

    @Log(title = "增加积分管理", businessType = BusinessType.INSERT)
    @PostMapping("/increase")
    public R<?> pointsIncrease(@RequestBody @Valid PointsIncreaseModel pointsIncreaseModel, String source)
    {
        log.info("增加积分参数为:{},{}", JSONObject.toJSONString(pointsIncreaseModel),source);
        RetryDTO retryDTO = new RetryDTO();
        //todo RetryDTO
        return R.ok(pointsService.pointsIncrease(pointsIncreaseModel,retryDTO));

    }


}
